cmake_minimum_required(VERSION 3.10..3.26)

project(example)
set(CMAKE_VERBOSE_MAKEFILE "ON")
#set(CMAKE_CXX_FLAGS "-Wall -Os -ggdb -std=c++14" )  
#-DCMAKE_CXX_STANDARD=17 

add_compile_options(-std=c++14)

include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/protos)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../protobuf/src)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../protobuf/third_party/abseil-cpp)

link_directories(${CMAKE_BINARY_DIR}/protobuf)
link_directories(${CMAKE_BINARY_DIR}/deps)

#link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../deps/pbmsg/build/Debug)

set(EX1_SRC_LIST ${CMAKE_CURRENT_SOURCE_DIR}/example1.cpp ${CMAKE_CURRENT_SOURCE_DIR}/protos/testmsg.pb.cc)
set(EX2_SRC_LIST ${CMAKE_CURRENT_SOURCE_DIR}/example2.cpp ${CMAKE_CURRENT_SOURCE_DIR}/protos/addressbook.pb.cc)
set(EX3_SRC_LIST ${CMAKE_CURRENT_SOURCE_DIR}/example3.cpp ${CMAKE_CURRENT_SOURCE_DIR}/protos/addressbook.pb.cc)
set(EX4_SRC_LIST ${CMAKE_CURRENT_SOURCE_DIR}/example4.cpp ${CMAKE_CURRENT_SOURCE_DIR}/protos/addressbook.pb.cc)
set(EX5_SRC_LIST ${CMAKE_CURRENT_SOURCE_DIR}/example5.cpp ${CMAKE_CURRENT_SOURCE_DIR}/protos/addressbook.pb.cc)
set(EX6_SRC_LIST ${CMAKE_CURRENT_SOURCE_DIR}/example6.cpp)
set(EX7_SRC_LIST ${CMAKE_CURRENT_SOURCE_DIR}/example7.cpp)
set(EX8_SRC_LIST ${CMAKE_CURRENT_SOURCE_DIR}/example8.cpp)
set(EX9_SRC_LIST ${CMAKE_CURRENT_SOURCE_DIR}/example9.cpp ${CMAKE_CURRENT_SOURCE_DIR}/protos/anydemo.pb.cc)

add_definitions(-DABSL_PROPAGATE_CXX_STD=ON)

link_libraries(libprotobuf)

add_executable(ex1 ${EX1_SRC_LIST})
add_executable(ex2 ${EX2_SRC_LIST})
add_executable(ex3 ${EX3_SRC_LIST})
add_executable(ex4 ${EX4_SRC_LIST})
add_executable(ex5 ${EX5_SRC_LIST})
add_executable(ex6 ${EX6_SRC_LIST})
add_executable(ex7 ${EX7_SRC_LIST})
add_executable(ex8 ${EX8_SRC_LIST})
add_executable(ex9 ${EX9_SRC_LIST})

add_dependencies(ex1 protoc)
add_dependencies(ex1 libprotoc)

# target_link_libraries(ex1
# libprotobuf)


# ./protoc.exe --proto_path=../../example/protos/ --cpp_out=../../example/protos/ --proto_path=../../protobuf/src anydemo.proto




# add_custom_command(
#     OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/protos/testmsg.pb.cc"
#             "${CMAKE_CURRENT_SOURCE_DIR}/protos/testmsg.pb.h" 
#             "${CMAKE_CURRENT_SOURCE_DIR}/protos/addressbook.pb.cc"
#             "${CMAKE_CURRENT_SOURCE_DIR}/protos/addressbook.pb.h" 
#     COMMAND ./protoc --proto_path=${CMAKE_CURRENT_SOURCE_DIR}/protos/ --cpp_out=${CMAKE_CURRENT_SOURCE_DIR}/protos/ testmsg.proto addressbook.proto
#     # DEPENDS myinput.txt  
#     MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/protos/testmsg.proto
#     WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
#     COMMENT "Generating testmsg file"  
# )

# add_custom_command(TARGET ex7
#     PRE_BUILD
#     COMMAND test -d ${CMAKE_BINARY_DIR}/deps || mkdir -p ${CMAKE_BINARY_DIR}/deps
#     COMMAND cd ${CMAKE_BINARY_DIR}/protobuf/third_party/ &&  find ./ -name '*.a' -exec cp {} ${CMAKE_BINARY_DIR}/deps \\\;
# )
